<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" :labelWidth="190" />
    <FilterTable ref="table" :columns="columns" :dataSource="tableList" :isSelectColumn="false" height="auto" :onColumnsChange="columns => (this.columns = columns)">
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle(1)" icon="el-icon-plus">新 增</multiuse-button>
        <multiuse-button size="small" type="primary" @click="addHandle(2)" icon="el-icon-plus">导 入</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="isaddCar" :title="'新增车辆'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <selectCar :carData="carData" @close="carcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="issearch" :title="'基本信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher :rowData="formData" @close="dealercloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="iscontract" :title="'选择合同'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <contract :dealerCode="dealerCode" @close="contractClose" />
    </BaseDialog>
    <BaseDialog :visible.sync="isProject" :title="'选择项目'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <AccountProject :dealerCode="dealerCode" @close="ProjectClose" />
    </BaseDialog>
    <BaseDialog :visible.sync="isDiscount" :title="'折扣详情'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DiscountDetail :rowData="DiscountData" @close="Discountclose" />
    </BaseDialog>
    <BaseDialog :visible.sync="isImport" :title="'导入'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <importFiles :carData="carData" @close="importcloseHandler" />
    </BaseDialog>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)" :disabled="isOpen || ischange">提 交</multiuse-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 3)" :disabled="ischange">保 存</multiuse-button>
    </div>
  </div>
</template>
<script>
import { getDetail, getAmount, getDiscount, getDiscountDetails, saveOrder, getNotPage, getDealerAddress, gettmFiAccountType, getAllDiscount } from '@/api/omSale/KeyCustomers/OrderSubmission/index.js';
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
import DiscountDetail from './DiscountDetail';
import AccountProject from './AccountProject';
import contract from './contract';
import selectCar from './selectCar';
import ownerSeacher from './ownerSeachers';
import Cookies from 'js-cookie';
import importFiles from './importFiles';
import { getAppId } from '@/assets/js/auth'; //获取登录用户

export default {
  data() {
    this.saveData = null;
    this.Amount = null;
    this.singleRebateFuelTotalAmount = null;
    this.buildRebateFuelTotalAmount = null;
    this.singleRebateEnergyTotalAmount = null;
    this.buildRebateEnergyTotalAmount = null;
    return {
      formList: this.createdFrom(),
      columns: this.createdTable(),
      tableList: [],
      isaddCar: false,
      formData: {},
      carData: {},
      json: {},
      isDiscount: false,
      DiscountData: {},
      TotalAmount: '',
      buildRebateFuelAmount: '',
      buildRebateEnergyAmount: '',
      rate: 0.5,
      cache: {},
      singleRebateFuelAmount: 0, //单车返利余额(油)
      singleRebateEnergyAmount: 0, //单车返利余额(电)
      buildRebateFuelAmountEnd: 0, //建店补贴单车带出池余额(油)
      buildRebateFuelAmountStart: 0, //建店补贴直接带出池余额(油)
      buildRebateEnergyAmountEnd: 0, //建店补贴单车带出池余额(电)
      buildRebateEnergyAmountStart: 0, //建店补贴直接带出池余额(电)
      singleRebateFuelAmountEdit: 0, //单车返利余额(油)
      singleRebateEnergyAmountEdit: 0, //单车返利余额(电)
      buildRebateFuelAmountEndEdit: 0, //建店补贴单车带出池余额(油)
      buildRebateFuelAmountStartEdit: 0, //建店补贴直接带出池余额(油)
      buildRebateEnergyAmountEndEdit: 0, //建店补贴单车带出池余额(电)
      buildRebateEnergyAmountStartEdit: 0, //建店补贴直接带出池余额(电)
      isowner: false,
      iscontract: false,
      isProject: false,
      contractId: '969',
      ProjectId: '',
      issearch: false,
      dealerCode: '',
      isOpen: false,
      ischange: false,
      isImport: false
    };
  },
  components: {
    DiscountDetail,
    AccountProject,
    contract,
    selectCar,
    ownerSeacher,
    importFiles
  },
  mounted() {
    this.table = this.$refs.table.$refs.pageTable;
    if (getAppId() != 'beijing') {
      this.formList.find(x => x.fieldName == 'remarks').hidden = true;
    }
  },
  props: ['rowData'],
  created() {
    this.getDetail(this.rowData);
  },
  mixins: [dictionary],
  methods: {
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '大客户订单信息'
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请选择',
          readonly: true,
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun(3)}></el-button>
              </div>
            );
          },
          change: p => {
            if (!p) {
              this.dealerCode = '';
              this.tableList = [];
            }
          },
          rules: [{ required: true, message: '请选择', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '合同名称',
          fieldName: 'majorContractName',
          placeholder: '请选择',
          readonly: true,
          initialValue: '123',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun(1)}></el-button>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '大客户项目名称',
          fieldName: 'majorProjectName',
          placeholder: '请选择',
          initialValue: '456',
          readonly: true,
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun(2)}></el-button>
              </div>
            );
          },
          rules: [{ required: true, message: '请选择', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '大客户名称',
          fieldName: 'majorCustomerName',
          placeholder: '请输入',
          initialValue: '789',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '大客户订单编号',
          fieldName: 'orderNo',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'DATE',
          label: '订单年月',
          fieldName: 'orderYearMonth',
          disabled: true,
          placeholder: '请输入',
          dateType: 'month',
          initialValue: moment().format('YYYY-MM')
        },
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          placeholder: '请选择',
          itemList: [
            { text: '直销大客户订单', value: 60061002 },
            { text: '区域大客户订单', value: 60061003 },
            { text: '代交车大客户订单', value: 60061004 }
          ],
          initialValue: 60061002,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {
            this.changeFrom();
            if (p) {
              this.formList.find(x => x.fieldName == 'orderDetailType').itemList = [];
              this.formList.find(x => x.fieldName == 'orderDetailType').initialValue = '';
              this.getNotPage(p);
            } else {
              this.formList.find(x => x.fieldName == 'orderDetailType').itemList = [];
              this.formList.find(x => x.fieldName == 'orderDetailType').initialValue = '';
            }
          }
        },
        {
          type: 'SELECT',
          label: '订单细分类型',
          fieldName: 'orderDetailType',
          placeholder: '请选择',
          itemList: [],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {
            this.changeFrom();
          }
        },
        {
          type: 'SELECT',
          label: '运输方式',
          fieldName: 'transportType',
          placeholder: '请选择',
          itemList: this.createDictList('6004'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {
            this.changeFrom();
          }
        },
        {
          type: 'SELECT',
          label: '是否使用返利',
          fieldName: 'isRebate',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: 10041001,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {
            this.changeFrom();
          }
        },
        {
          type: 'INPUT',
          precision: 2,
          label: '资金总余额(油)',
          fieldName: 'totalFuelAmount',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT',
          precision: 2,
          label: '资金总余额(电)',
          fieldName: 'totalEnergyAmount',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          initialValue: 0.0,
          label: '单车返利余额(电)',
          fieldName: 'singleRebateEnergyAmount',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          initialValue: 0.0,
          label: '建店补贴直接带出池余额(电)',
          fieldName: 'buildRebateEnergyAmountStart',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          initialValue: 0.0,
          label: '建店补贴单车带出池余额(电)',
          fieldName: 'buildRebateEnergyAmountEnd',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          initialValue: 0.0,
          label: '单车返利余额(油)',
          fieldName: 'singleRebateFuelAmount',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          initialValue: 0.0,
          label: '建店补贴直接带出池余额(油)',
          fieldName: 'buildRebateFuelAmountStart',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '建店补贴单车带出池余额(油)',
          fieldName: 'buildRebateFuelAmountEnd',
          placeholder: '请选择',
          precision: 2,
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '单车返利使用金额(电)',
          fieldName: 'singleRebateEnergyTotalAmount',
          placeholder: '请选择',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '建店补贴直接带出池使用金额(电)',
          fieldName: 'buildRebateEnergyTotalAmountStart',
          placeholder: '请选择',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '建店补贴单车带出池使用金额(电)',
          fieldName: 'buildRebateEnergyTotalAmount',
          placeholder: '请选择',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '单车返利使用金额(油)',
          fieldName: 'singleRebateFuelTotalAmount',
          placeholder: '请选择',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '建店补贴直接带出池使用金额(油)',
          fieldName: 'buildRebateFuelTotalAmountStart',
          placeholder: '请选择',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '建店补贴单车带出池使用金额(油)',
          fieldName: 'buildRebateFuelTotalAmount',
          placeholder: '请选择',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '实付总金额',
          fieldName: 'realPayTotalAmount',
          initialValue: 0.0,
          disabled: true
        },
        {
          type: 'DATE',
          label: '要求交付日期',
          fieldName: 'requiredDeliveryDate',
          placeholder: '请选择',
          dateType: 'exactdate'
        },
        {
          type: 'SELECT',
          label: '开票类型',
          fieldName: 'invoiceType',
          placeholder: '请选择',
          itemList: this.createDictList('6044'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        // 2021-4-27 19:11:03  qinjh 泳哥让动力形式、资金类型 隐藏掉；
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择',
          hidden: true,
          itemList: this.createDictList('6008'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {
            this.tableList = [];
            if (p) {
              this.formList.map(x => {
                if (x.fieldName == 'accountId') {
                  x.initialValue = '';
                  x.itemList = [];
                }
              });
              this.gettmFiAccountType(p);
            } else {
              this.formList.map(x => {
                if (x.fieldName == 'accountId') {
                  x.initialValue = '';
                  x.itemList = [];
                }
              });
            }
          }
        },
        {
          type: 'SELECT',
          label: '资金类型',
          fieldName: 'accountId',
          placeholder: '请选择',
          hidden: true,
          itemList: [],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {
            if (p) {
              this.getAmountDetail(this.dealerCode, p);
            }
          }
        },
        {
          type: 'INPUT',
          label: '审批识别码',
          fieldName: 'remarks',
          hidden: false,
          rules: [{ required: true, message: '请填写OA的审批号', trigger: 'blur' }],
          placeholder: '请填写OA的审批号'
        },
        {
          type: 'BREAK_SPACE',
          label: '车辆信息'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 120,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 1)}>
                  删除
                </multiuse-button>
              </div>
            );
          }
        },

        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '数量',
          dataIndex: 'orderNum',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editRequired: true,
          editPattern: /^[1-9]\d*$/,
          summation: true,
          defaultEditable: true,
          rules: [{ required: true, message: '请填写正整数', trigger: 'blur' }],
          onInput: (index, data) => {
            this.changeNum(index, data);
          }
        },
        {
          title: '市场指导价',
          dataIndex: 'singleAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '国补金额',
          dataIndex: 'subsidyAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折前单价',
          dataIndex: 'beforeSingleAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣总金额',
          dataIndex: 'discountTotalAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          precision: 2,
          render: p => {
            return (
              <span class="discount" onClick={() => this.editHandle(p.row, 2)}>
                {p.row.discountTotalAmount}
              </span>
            );
          }
        },
        {
          title: '单车返利总金额',
          dataIndex: 'singleRebateTotalAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          precision: 2
        },
        {
          title: '建店返利类型',
          dataIndex: 'buildRebateType',
          sorter: true,
          filter: true,
          initialValue: 60361003,
          filterType: 'checkbox',
          editable: false,
          filterItems: this.createDictList('6036').filter(x => x.value !== 60361001),
          editType: 'select',
          editItems: this.createDictList('6036').filter(x => x.value !== 60361001)
          // render: p => {
          //   return (
          //     <el-select
          //       size="mini"
          //       v-model={p.row.buildRebateType}
          //       placeholder="请选择"
          //       onChange={value => {
          //         p.row.buildRebateType = value;
          //         this.buildRebateTypeChange();
          //       }}
          //     >
          //       {this.createDictList('6036')
          //         .filter(x => x.value !== 60361001)
          //         .map(item => (
          //           <el-option key={item.value} label={item.text} value={item.value} />
          //         ))}
          //     </el-select>
          //   );
          // }
        },
        {
          title: '建店返利总金额',
          dataIndex: 'buildRebateTotalAmountLocalShow',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '单车返利金额',
          dataIndex: 'singleRebateAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          hidden: true
        },
        {
          title: '建店返利金额',
          dataIndex: 'buildRebateAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          hidden: true
        },
        {
          title: '折后单价',
          dataIndex: 'afterDiscountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折前总金额',
          dataIndex: 'totalAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true
        },
        {
          title: '折后总金额',
          dataIndex: 'afterTotalAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          precision: 2
        },
        {
          title: '收车地址',
          dataIndex: 'addressId',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: p => {
            return (
              <el-select
                size="mini"
                v-model={p.row.addressId}
                placeholder="请选择"
                onChange={value => {
                  p.row.addressId = value;
                }}
              >
                {p.row.addressList.map(item => (
                  <el-option key={item.value} label={item.text} value={item.value} />
                ))}
              </el-select>
            );
          }
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'text'
        }
      ];
    },
    changeValueNum(a) {
      if (!a || a == null || isNaN(a)) {
        return 0;
      } else {
        return a;
      }
    },
    // 新增车辆
    addHandle(type) {
      this.$refs.from.SUBMIT_FORM();
      if (this.saveData) {
        let json = JSON.parse(JSON.stringify(this.saveData));
        json.dealerCode = this.dealerCode;
        this.carData = json;
        if (type == 1) {
          this.isaddCar = true;
        } else {
          this.isImport = true;
        }
        this.saveData = null;
      }
    },
    async changeFrom() {
      if (this.tableList.length < 1) {
        return;
      }
      this.$refs.from.SUBMIT_FORM();
      if (this.saveData) {
        this.ischange = true;
        let json = JSON.parse(JSON.stringify(this.saveData));
        let list = this.tableList || [];
        let res = await getAllDiscount({
          saveType: 'OEM',
          dealerCode: this.dealerCode,
          orderType: json.orderType,
          orderDetailType: json.orderDetailType,
          transportType: json.transportType,
          isRebate: json.isRebate,
          detailDTOList: list
        });
        this.tableList.map(x => {
          res.data.map(y => {
            if (x.productCode == y.productCode) {
              console.log(x, y, '222');
              x.singleRebate = y.singleRebate;
              x.bulidRebate = y.bulidRebate;
              x.afterDiscountAmount = y.afterDiscountAmount;
              x.beforeSingleAmount = y.beforeSingleAmount;
              x.singleAmount = y.singleAmount;
              x.subsidyAmount = y.subsidyAmount;
              x.buildRebateAmount = y.bulidRebate;
              x.singleRebateAmount = y.singleRebate;
              x.bulidRebateEnd = y.bulidRebateEnd;
              x.policyId = y.policyId;
            }
          });
        });
        console.log('tableList', this.tableList);
        this.resetCache();
        this.tableList.map(x => {
          this.reComputedTable(x);
        });
        this.reComputedForm();
        this.ischange = false;
      }
    },
    async changeFroms(data) {
      if (this.tableList.length < 1) {
        return;
      }
      console.log(this.formList);

      this.ischange = true;
      let json = JSON.parse(JSON.stringify(data));
      let list = this.tableList || [];
      // list.map(x => {
      //   x.powerType = 60081001;
      // });
      let res = await getAllDiscount({
        saveType: 'OEM',
        dealerCode: this.dealerCode,
        orderType: json.orderType,
        orderDetailType: json.orderDetailType,
        transportType: json.transportType,
        isRebate: json.isRebate,
        detailDTOList: list
      });
      this.tableList.map(x => {
        res.data.map(y => {
          if (x.productCode == y.productCode) {
            console.log(x, y, '222');
            x.singleRebate = y.singleRebate;
            x.bulidRebate = y.bulidRebate;
            x.afterDiscountAmount = y.afterDiscountAmount;
            x.beforeSingleAmount = y.beforeSingleAmount;
            x.singleAmount = y.singleAmount;
            x.subsidyAmount = y.subsidyAmount;
            x.buildRebateAmount = y.bulidRebate;
            x.singleRebateAmount = y.singleRebate;
            x.bulidRebateEnd = y.bulidRebateEnd;
            x.policyId = y.policyId;
            x.discountAmount = y.discountAmount;
          }
        });
      });

      console.log('changeFrom', this.tableList);
      this.resetCache();
      this.tableList.map(x => {
        this.reComputedTable(x);
      });

      this.reComputedForm();
      this.ischange = false;
    },
    changeList(list) {
      this.resetCache(); //重置余额池

      this.tableList.map(x => {
        this.reComputedTable(x);
      });
      this.reComputedForm();
    },
    seacherFun(type) {
      if (type == 1) {
        if (this.dealerCode) {
          this.iscontract = true;
        } else {
          this.$notify({
            title: '警告',
            message: '请选择经销商',
            type: 'warning'
          });
          return;
        }
      } else if (type == 2) {
        if (this.dealerCode) {
          this.isProject = true;
        } else {
          this.$notify({
            title: '警告',
            message: '请选择经销商',
            type: 'warning'
          });
          return;
        }
      } else {
        this.issearch = true;
      }
    },
    async getAmountDetail(code, accountId) {
      let json = {};
      if (!accountId) {
        json = { dealerCode: code };
      } else {
        json = { dealerCode: code, accountId: accountId };
      }
      let res = await getAmount(json);

      for (let i in res.data) {
        this.formList.map(x => {
          if (x.fieldName == i) {
            x.initialValue = res.data[i];
          }
        });
      }
      this.json = res.data;
      // 燃油车
      this.singleRebateFuelTotalAmount = res.data.singleRebateFuelAmount > 0 ? res.data.singleRebateFuelAmount : 0; //单车返利余额(油)
      this.buildRebateFuelTotalAmount = res.data.buildRebateFuelAmountEnd > 0 ? res.data.buildRebateFuelAmountEnd : 0;
      this.singleRebateFuelAmount = res.data.singleRebateFuelAmount > 0 ? res.data.singleRebateFuelAmount : 0;
      this.buildRebateFuelAmountEnd = res.data.buildRebateFuelAmountEnd > 0 ? res.data.buildRebateFuelAmountEnd : 0; //建油尾余额
      this.buildRebateFuelAmountStart = res.data.buildRebateFuelAmountStart > 0 ? res.data.buildRebateFuelAmountStart : 0; //建油尾余额
      //电动车
      this.singleRebateEnergyTotalAmount = res.data.singleRebateEnergyAmount > 0 ? res.data.singleRebateEnergyAmount : 0;
      this.buildRebateEnergyTotalAmount = res.data.buildRebateEnergyAmountEnd > 0 ? res.data.buildRebateEnergyAmountEnd : 0;
      this.singleRebateEnergyAmount = res.data.singleRebateEnergyAmount > 0 ? res.data.singleRebateEnergyAmount : 0;
      this.buildRebateEnergyAmountEnd = res.data.buildRebateEnergyAmountEnd > 0 ? res.data.buildRebateEnergyAmountEnd : 0; //建电尾余额
      this.buildRebateEnergyAmountStart = res.data.buildRebateEnergyAmountStart > 0 ? res.data.buildRebateEnergyAmountStart : 0; //建电尾余额
      this.cache.singleRebateFuelAmount = this.singleRebateFuelAmount; //单车返利余额(油)
      this.cache.singleRebateEnergyAmount = this.singleRebateEnergyAmount; //单车返利余额(电)
      this.cache.buildRebateFuelAmountEnd = this.buildRebateFuelAmountEnd; //建店补贴单车带出池余额(油)
      this.cache.buildRebateFuelAmountStart = this.buildRebateFuelAmountStart; //建店补贴直接带出池余额(油)
      this.cache.buildRebateEnergyAmountEnd = this.buildRebateEnergyAmountEnd; //建店补贴单车带出池余额(电)
      this.cache.buildRebateEnergyAmountStart = this.buildRebateEnergyAmountStart; //建店补贴直接带出池余额(电)
      console.log(code, res.data, '余额池');
    },
    async getNotPage(orderType) {
      let list = await getNotPage({ orderType: orderType, isAvailable: 10041001 });
      let dataList = list.data.map(x => ({ text: x.subName, value: x.subId }));
      this.formList.map(x => {
        if (x.fieldName == 'orderDetailType') {
          x.itemList = dataList;
          if (dataList.length > 0) {
            x.initialValue = dataList[0].value;
          }
        }
      });
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else if (type == 2) {
        if (this.tableList.length < 1) {
          this.$notify({
            title: '警告',
            message: '请选择车辆',
            type: 'warning'
          });
          return;
        }
        this.$refs.from.SUBMIT_FORM();
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          let arr = this.tableList;
          let is = false;
          arr.map(x => {
            if (Number(x.orderNum) > 10000000000 || Number(x.orderNum) < 1) {
              is = true;
            }
            x.buildRebateTotalAmount = Number(x.buildRebateTotalAmount).toFixed(2);
            x.singleRebateTotalAmount = Number(x.singleRebateTotalAmount).toFixed(2);
            x.buildRebateTotalAmountStart = Number(x.buildRebateTotalAmountStart).toFixed(2);
            x.rebateTotalAmount = (Number(x.buildRebateTotalAmount) + Number(x.buildRebateTotalAmountStart) + Number(x.singleRebateTotalAmount)).toFixed(2);
          });
          if (is) {
            this.$notify({
              title: '警告',
              message: '输入数量过大或过小',
              type: 'warning'
            });
            return;
          }
          json.orderId = this.rowData.orderId;
          json.detailDTOList = arr;
          json.totalFuelAmount = this.changeValueNum(this.json.totalFuelAmount);
          json.totalEnergyAmount = this.changeValueNum(this.json.totalEnergyAmount);

          json.buildRebateEnergyAmountEnd = this.changeValueNum(this.json.buildRebateEnergyAmountEnd);
          json.buildRebateEnergyAmountStart = this.changeValueNum(this.json.buildRebateEnergyAmountStart);
          json.buildRebateFuelAmountEnd = this.changeValueNum(this.json.buildRebateFuelAmountEnd);
          json.buildRebateFuelAmountStart = this.changeValueNum(this.json.buildRebateFuelAmountStart);

          json.singleRebateEnergyAmount = this.changeValueNum(this.json.singleRebateEnergyAmount);
          json.singleRebateFuelAmount = this.changeValueNum(this.json.singleRebateFuelAmount);
          if (
            json.realPayTotalAmount > 1000000000 ||
            json.buildRebateEnergyTotalAmount > 1000000000 ||
            json.singleRebateEnergyTotalAmount > 1000000000 ||
            json.buildRebateFuelTotalAmount > 1000000000 ||
            json.singleRebateFuelTotalAmount > 1000000000
          ) {
            this.$notify({
              title: '警告',
              message: '实付总金额或返利金额数额过大，请重新进行保存',
              type: 'warning'
            });
            return;
          }
          json.realPayTotalAmount = this.changeValueNum(Number(json.realPayTotalAmount).toFixed(2));
          json.buildRebateEnergyAmountEnd = this.changeValueNum(Number(json.buildRebateEnergyAmountEnd).toFixed(2));
          json.singleRebateEnergyAmount = this.changeValueNum(Number(json.singleRebateEnergyAmount).toFixed(2));
          json.singleRebateEnergyTotalAmount = this.changeValueNum(Number(json.singleRebateEnergyTotalAmount).toFixed(2));
          json.buildRebateEnergyTotalAmount = this.changeValueNum(Number(json.buildRebateEnergyTotalAmount).toFixed(2));
          json.buildRebateFuelAmountEnd = this.changeValueNum(Number(json.buildRebateFuelAmountEnd).toFixed(2));
          json.singleRebateFuelAmount = this.changeValueNum(Number(json.singleRebateFuelAmount).toFixed(2));
          json.singleRebateFuelTotalAmount = this.changeValueNum(Number(json.singleRebateFuelTotalAmount).toFixed(2));
          json.buildRebateFuelTotalAmount = this.changeValueNum(Number(json.buildRebateFuelTotalAmount).toFixed(2));
          json.buildRebateEnergyAmountStart = this.changeValueNum(Number(json.buildRebateEnergyAmountStart).toFixed(2));
          json.buildRebateFuelAmountStart = this.changeValueNum(Number(json.buildRebateFuelAmountStart).toFixed(2));
          json.majorContractNo = this.contractId;
          json.projectCode = this.ProjectId;
          json.dealerCode = this.dealerCode;
          json.saveType = 'OEM';
          json.orderStatus = 60431003;
          json.orderMonth = json.orderYearMonth.split('-')[1];
          json.orderYear = json.orderYearMonth.split('-')[0];
          json.realPayTotalAmount = this.changeValueNum(json.realPayTotalAmount);
          json.buildRebateEnergyAmountEnd = this.changeValueNum(json.buildRebateEnergyAmountEnd);
          json.singleRebateEnergyAmount = this.changeValueNum(json.singleRebateEnergyAmount);
          json.singleRebateEnergyTotalAmount = this.changeValueNum(json.singleRebateEnergyTotalAmount);
          json.buildRebateEnergyTotalAmount = this.changeValueNum(json.buildRebateEnergyTotalAmount);
          json.buildRebateFuelAmountEnd = this.changeValueNum(json.buildRebateFuelAmountEnd);
          json.singleRebateFuelAmount = this.changeValueNum(json.singleRebateFuelAmount);
          json.singleRebateFuelTotalAmount = this.changeValueNum(json.singleRebateFuelTotalAmount);
          json.buildRebateFuelTotalAmount = this.changeValueNum(json.buildRebateFuelTotalAmount);
          json.buildRebateEnergyAmountStart = this.changeValueNum(json.buildRebateEnergyAmountStart);
          json.buildRebateFuelAmountStart = this.changeValueNum(json.buildRebateFuelAmountStart);
          let res = await saveOrder(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '提交成功',
              type: 'success'
            });
            this.$emit('close', json);
          } else {
            this.saveData = null;
          }
        }
      } else {
        if (this.tableList.length < 1) {
          this.$notify({
            title: '警告',
            message: '请选择车辆',
            type: 'warning'
          });
          return;
        }
        this.$refs.from.SUBMIT_FORM();
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          let arr = this.tableList;
          let is = false;
          arr.map(x => {
            if (Number(x.orderNum) > 10000000000 || Number(x.orderNum) < 1) {
              is = true;
            }
            x.buildRebateTotalAmount = this.changeValueNum(Number(x.buildRebateTotalAmount).toFixed(2));
            x.singleRebateTotalAmount = this.changeValueNum(Number(x.singleRebateTotalAmount).toFixed(2));
            x.buildRebateTotalAmountStart = this.changeValueNum(Number(x.buildRebateTotalAmountStart).toFixed(2));
            x.rebateTotalAmount = this.changeValueNum((Number(x.buildRebateTotalAmount) + Number(x.buildRebateTotalAmountStart) + Number(x.singleRebateTotalAmount)).toFixed(2));
          });
          if (is) {
            this.$notify({
              title: '警告',
              message: '输入数量过大或过小',
              type: 'warning'
            });
            return;
          }
          json.orderId = this.rowData.orderId;
          json.detailDTOList = arr;
          json.majorContractNo = this.contractId;
          json.projectCode = this.ProjectId;
          json.totalAmount = this.json.totalAmount;
          json.dealerCode = this.dealerCode;
          json.totalFuelAmount = this.changeValueNum(this.json.totalFuelAmount);
          json.totalEnergyAmount = this.changeValueNum(this.json.totalEnergyAmount);

          json.buildRebateEnergyAmountEnd = this.changeValueNum(this.json.buildRebateEnergyAmountEnd);
          json.buildRebateEnergyAmountStart = this.changeValueNum(this.json.buildRebateEnergyAmountStart);
          json.buildRebateFuelAmountEnd = this.changeValueNum(this.json.buildRebateFuelAmountEnd);
          json.buildRebateFuelAmountStart = this.changeValueNum(this.json.buildRebateFuelAmountStart);

          json.singleRebateEnergyAmount = this.changeValueNum(this.json.singleRebateEnergyAmount);
          json.singleRebateFuelAmount = this.changeValueNum(this.json.singleRebateFuelAmount);
          if (json.realPayTotalAmount > 1000000000 || json.buildRebateTotalAmount > 1000000000 || json.singleRebateTotalAmount > 1000000000) {
            this.$notify({
              title: '警告',
              message: '实付总金额或返利金额数额过大，请重新进行保存',
              type: 'warning'
            });
            return;
          }
          json.realPayTotalAmount = this.changeValueNum(Number(json.realPayTotalAmount).toFixed(2));
          json.buildRebateFuelTotalAmountStart = this.changeValueNum(Number(json.buildRebateFuelTotalAmountStart).toFixed(2));
          json.buildRebateEnergyTotalAmountStart = this.changeValueNum(Number(json.buildRebateEnergyTotalAmountStart).toFixed(2));
          json.buildRebateEnergyAmountEnd = this.changeValueNum(Number(json.buildRebateEnergyAmountEnd).toFixed(2));
          json.buildRebateEnergyAmountStart = this.changeValueNum(Number(json.buildRebateEnergyAmountStart).toFixed(2));
          json.singleRebateEnergyAmount = this.changeValueNum(Number(json.singleRebateEnergyAmount).toFixed(2));
          json.singleRebateEnergyTotalAmount = this.changeValueNum(Number(json.singleRebateEnergyTotalAmount).toFixed(2));
          json.buildRebateEnergyTotalAmount = this.changeValueNum(Number(json.buildRebateEnergyTotalAmount).toFixed(2));
          json.buildRebateFuelAmountEnd = this.changeValueNum(Number(json.buildRebateFuelAmountEnd).toFixed(2));
          json.buildRebateFuelAmountStart = this.changeValueNum(Number(json.buildRebateFuelAmountStart).toFixed(2));
          json.singleRebateFuelAmount = this.changeValueNum(Number(json.singleRebateFuelAmount).toFixed(2));
          json.singleRebateFuelTotalAmount = this.changeValueNum(Number(json.singleRebateFuelTotalAmount).toFixed(2));
          json.buildRebateFuelTotalAmount = this.changeValueNum(Number(json.buildRebateFuelTotalAmount).toFixed(2));
          json.orderMonth = json.orderYearMonth.split('-')[1];
          json.orderYear = json.orderYearMonth.split('-')[0];
          json.saveType = 'OEM';
          json.orderStatus = 60431001;
          json.realPayTotalAmount = this.changeValueNum(json.realPayTotalAmount);
          json.buildRebateFuelTotalAmountStart = this.changeValueNum(json.buildRebateFuelTotalAmountStart);
          json.buildRebateEnergyTotalAmountStart = this.changeValueNum(json.buildRebateEnergyTotalAmountStart);
          json.buildRebateEnergyAmountEnd = this.changeValueNum(json.buildRebateEnergyAmountEnd);
          json.buildRebateEnergyAmountStart = this.changeValueNum(json.buildRebateEnergyAmountStart);
          json.singleRebateEnergyAmount = this.changeValueNum(json.singleRebateEnergyAmount);
          json.singleRebateEnergyTotalAmount = this.changeValueNum(json.singleRebateEnergyTotalAmount);
          json.buildRebateEnergyTotalAmount = this.changeValueNum(json.buildRebateEnergyTotalAmount);
          json.buildRebateFuelAmountEnd = this.changeValueNum(json.buildRebateFuelAmountEnd);
          json.buildRebateFuelAmountStart = this.changeValueNum(json.buildRebateFuelAmountStart);
          json.singleRebateFuelAmount = this.changeValueNum(json.singleRebateFuelAmount);
          json.singleRebateFuelTotalAmount = this.changeValueNum(json.singleRebateFuelTotalAmount);
          json.buildRebateFuelTotalAmount = this.changeValueNum(json.buildRebateFuelTotalAmount);
          let res = await saveOrder(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success'
            });
            this.$emit('close', json);
          } else {
            this.saveData = null;
          }
        }
      }
    },
    async carcloseHandler(val, carData) {
      this.isaddCar = false;
      if (val && val.length > 0) {
        // let is = false;
        let arr = [];
        if (this.tableList && this.tableList.length > 0) {
          arr = val.filter(x => !this.tableList.find(y => y.productCode == x.productCode));
        } else {
          arr = val;
        }
        arr.map(async x => {
          await this.getDisecount(x, carData);
        });

        // if (!is) {
        //   // await this.getAddress(val)
        //   await this.getDisecount(val, carData);
        // } else {
        //   // 提示
        //   this.$notify({
        //     title: '警告',
        //     message: '列表已有该车辆',
        //     type: 'warning'
        //   });
        //   return;
        // }
      }
    },
    Discountclose() {
      this.isDiscount = false;
    },
    importcloseHandler(val) {
      console.log(val);
      if (val.length > 0) {
        let is = false;
        val.map(x => {
          this.tableList.map(y => {
            if (x.productCode == y.productCode) {
              is = true;
            }
          });
        });
        if (is) {
          // 提示
          this.$notify({
            title: '警告',
            message: '列表已有导入的车辆,请不要重复添加',
            type: 'warning'
          });
          return;
        }
        this.resetCache();
        val.map(x => {
          //todo 待测试
          this.reComputedTable(x);
          let str = false;
          x.addressList = x.addressList.map(y => ({ text: y.detaildAddress, value: y.addressId, addressProperty: y.addressProperty }));
          x.addressList.map(y => {
            if (y.addressProperty == 60351001) {
              str = y.value;
            }
          });
          x.addressId = str ? str : x.addressList[0].value;
        });
        this.table.EXECUTE_INSERT(val);

        this.reComputedForm();
      }
      this.isImport = false;
    },
    // 加载折扣信息
    async getDisecount(data, carData) {
      let res = await getDiscount({
        saveType: 'OEM',
        orderType: carData.orderType,
        orderDetailType: carData.orderDetailType,
        transportType: carData.transportType,
        isRebate: carData.isRebate,
        dealerCode: carData.dealerCode,
        detailDTOList: [
          {
            modelCode: data.modelCode,
            singleAmount: data.basicPrice,
            powerType: data.powerType,
            optionId: data.optionId,
            optionCode: data.optionCode,
            subsidyAmount: data.subsidyAmount,
            productCode: data.productCode
          }
        ]
      });

      console.log(data, 'data');
      console.log(res.data, 'res.data');
      res.data.buildRebateType = 60361003; //默认店首逻辑

      let rowData = this.reComputedTable(Object.assign({}, data, res.data));
      let obj = (await getDealerAddress({ dealerCode: this.dealerCode, powerType: rowData.powerType })).data.map(x => ({
        text: x.detaildAddress,
        value: x.addressId,
        addressProperty: x.addressProperty
      }));
      let json = Object.assign({}, carData, rowData);
      json.addressList = obj;
      let str = false;
      obj.map(x => {
        if (x.addressProperty == 60351001) {
          str = x.value;
        }
      });
      json.addressId = str ? str : obj[0].value;
      json.buildRebateAmount = json.bulidRebateEnd;
      json.singleRebateAmount = json.singleRebate;
      json.buildRebateType = 60361003;
      console.log(json, 'json');
      this.table.EXECUTE_INSERT([json]);

      this.reComputedForm();
    },
    //改变首尾计算规则
    buildRebateTypeChange() {
      this.resetCache();
      this.tableList.map(x => {
        this.reComputedTable(x);
      });
      this.reComputedForm();
    },
    changeNum(index, data) {
      console.log(index, data, '改变数量');
      let num = '';
      let str = '';
      for (let i in index) {
        num = index[i];
        console.log(i, 'i');
        str = i.split('|')[0];
      }
      let Rep = /^[1-9]\d*$/;
      console.log(num, Rep.test(num));
      if (Rep.test(num)) {
        this.resetCache();
        this.tableList.map(x => {
          // if (x._uid == str) {
          this.reComputedTable(x);
        });

        this.reComputedForm();
      }
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async editHandle(data, type) {
      if (type == 1) {
        await this.$confirm('是否确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(async () => {
            this.table.EXECUTE_DELETE([data]);
            console.log(this.tableList, '删除了');
            this.changeList(this.tableList);
          })
          .catch(() => {});
      } else {
        this.DiscountData = data;
        this.isDiscount = true;
      }
    },
    // 合同返回
    contractClose(val) {
      if (val) {
        this.formList.map(x => {
          if (x.fieldName == 'majorContractName') {
            x.initialValue = val.contractName;
            this.contractId = val.contractNum;
          }
        });
      }
      this.iscontract = false;
    },
    // 加载资金类型
    async gettmFiAccountType(powerType) {
      let res = (await gettmFiAccountType({ powerType: powerType, fundsType: 0, ownerCode: this.dealerCode })).data.map(x => ({ text: x.accountName, value: x.id }));
      this.formList.find(x => x.fieldName == 'accountId').itemList = res;
    },
    ProjectClose(val) {
      if (val) {
        this.formList.map(x => {
          if (x.fieldName == 'majorProjectName') {
            x.initialValue = val.projectName;
            this.ProjectId = val.projectCode;
          }
          if (x.fieldName == 'majorCustomerName') {
            x.initialValue = val.customerName;
          }
        });
      }
      this.isProject = false;
    },
    DiscountClose() {
      this.isDiscount = false;
    },
    // 获取详情
    async getDetail(data) {
      let res = await getDetail({ orderId: data.orderId });

      // 赋值
      this.singleRebateFuelAmountEdit = res.data.singleRebateFuelTotalAmount ? res.data.singleRebateFuelTotalAmount : 0;
      this.singleRebateEnergyAmountEdit = res.data.singleRebateEnergyTotalAmount ? res.data.singleRebateEnergyTotalAmount : 0;
      this.buildRebateFuelAmountEndEdit = res.data.buildRebateFuelTotalAmount ? res.data.buildRebateFuelTotalAmount : 0;
      this.buildRebateFuelAmountStartEdit = res.data.buildRebateFuelTotalAmountStart ? res.data.buildRebateFuelTotalAmountStart : 0;
      this.buildRebateEnergyAmountEndEdit = res.data.buildRebateEnergyTotalAmount ? res.data.buildRebateEnergyTotalAmount : 0;
      this.buildRebateEnergyAmountStartEdit = res.data.buildRebateEnergyTotalAmountStart ? res.data.buildRebateEnergyTotalAmountStart : 0;
      for (let i in res.data) {
        this.formList.map(x => {
          if (x.fieldName == 'buildRebateEnergyAmount') {
          } else if (x.fieldName == 'buildRebateFuelAmount') {
          } else if (x.fieldName == 'singleRebateEnergyAmount') {
          } else if (x.fieldName == 'singleRebateFuelAmount') {
          } else if (x.fieldName == 'totalEnergyAmount') {
          } else if (x.fieldName == 'totalFuelAmount') {
          } else if (i == x.fieldName) {
            x.initialValue = res.data[i];
          }
        });
      }
      this.contractId = res.data.majorContractNo;
      this.ProjectId = res.data.projectCode;
      this.dealerCode = res.data.dealerCode;
      await this.getNotPage(res.data.orderType);
      this.formList.find(x => x.fieldName == 'orderDetailType').initialValue = res.data.orderDetailType;
      await this.getAmountDetail(res.data.dealerCode, res.data.accountId);
      this.gettmFiAccountType(res.data.powerType);
      res.data.detailDTOList.map(x => {
        x.buildRebateTotalAmountLocalShow = ((x.buildRebateTotalAmountStart ? x.buildRebateTotalAmountStart : 0) + (x.buildRebateTotalAmount ? x.buildRebateTotalAmount : 0)).toFixed(2);
        x.addressList = x.addressList.map(x => ({ text: x.detaildAddress, value: x.addressId, addressProperty: x.addressProperty, isnew: false }));
      });
      if (this.rowData.orderStatus == 60431002) {
        this.isOpen = true;
      } else {
        this.isOpen = false;
      }
      this.tableList = res.data.detailDTOList || [];

      this.changeFroms(res.data);
    },
    dealercloseHandler(val) {
      if (val) {
        this.formList.find(x => x.fieldName == 'dealerName').initialValue = val.dealerName;
        this.dealerCode = val.dealerCode;
        this.getAmountDetail(this.dealerCode, '');
        this.tableList = [];
        this.contractId = '';
        this.ProjectId = '';
        this.formList.map(x => {
          if (x.fieldName == 'majorProjectName') {
            x.initialValue = '';
          }
          if (x.fieldName == 'majorContractName') {
            x.initialValue = '';
          }
          if (x.fieldName == 'majorCustomerName') {
            x.initialValue = '';
          }
          if (x.fieldName == 'accountId') {
            x.initialValue = '';
            x.itemList = [];
          }
        });
        let str = this.formList.find(x => x.fieldName == 'powerType').initialValue;
        if (str) {
          this.gettmFiAccountType(str);
        }
      }
      this.issearch = false;
    },
    resetCache() {
      this.singleRebateEnergyAmount = this.singleRebateEnergyTotalAmount;
      this.buildRebateEnergyAmountEnd = this.buildRebateEnergyTotalAmount;
      this.singleRebateFuelAmount = this.singleRebateFuelTotalAmount;
      this.buildRebateFuelAmountEnd = this.buildRebateFuelTotalAmount;
      this.singleRebateFuelAmount = this.cache.singleRebateFuelAmount; //单车返利余额(油)
      this.singleRebateEnergyAmount = this.cache.singleRebateEnergyAmount; //单车返利余额(电)
      this.buildRebateFuelAmountEnd = this.cache.buildRebateFuelAmountEnd; //建店补贴单车带出池余额(油)
      this.buildRebateFuelAmountStart = this.cache.buildRebateFuelAmountStart; //建店补贴直接带出池余额(油)
      this.buildRebateEnergyAmountEnd = this.cache.buildRebateEnergyAmountEnd; //建店补贴单车带出池余额(电)
      this.buildRebateEnergyAmountStart = this.cache.buildRebateEnergyAmountStart; //建店补贴直接带出池余额(电)
    },
    reComputedForm() {
      // 计算单车返利总金额和建店返利增金额 实付总金额
      let singleEnergytotalAmount = 0;
      let buildEnergytotalAmount = 0;
      let singleFueltotalAmount = 0;
      let buildFueltotalAmount = 0;
      let afterTotalAmount = 0;
      let buildRebateEnergyAmountStart = 0;
      // let buildRebateEnergyAmountEnd = 0;
      let buildRebateFuelAmountStart = 0;
      // let buildRebateFuelAmountEnd = 0;
      this.tableList.map(x => {
        if (x.powerType == 60081001) {
          x.singleRebateTotalAmount = x.singleRebateTotalAmount ? x.singleRebateTotalAmount : 0;
          singleFueltotalAmount = Number(x.singleRebateTotalAmount) + Number(singleFueltotalAmount);
          buildFueltotalAmount = Number(x.buildRebateTotalAmount) + Number(buildFueltotalAmount);
          buildRebateFuelAmountStart = Number(x.buildRebateTotalAmountStart) + Number(buildRebateFuelAmountStart);
          // buildRebateFuelAmountEnd=x.buildRebateTotalAmount+buildRebateFuelAmountEnd
        } else if (x.powerType == 60081002) {
          singleEnergytotalAmount = Number(x.singleRebateTotalAmount) + Number(singleEnergytotalAmount);
          buildEnergytotalAmount = Number(x.buildRebateTotalAmount) + Number(buildEnergytotalAmount);
          buildRebateEnergyAmountStart = Number(x.buildRebateTotalAmountStart) + Number(buildRebateEnergyAmountStart);
          // buildRebateEnergyAmountEnd=x.buildRebateTotalAmount+buildRebateEnergyAmountEnd
        }
        afterTotalAmount = Number(x.afterTotalAmount) - Number(x.singleRebateTotalAmount) - Number(x.buildRebateTotalAmount) - Number(x.buildRebateTotalAmountStart) + Number(afterTotalAmount);
      });
      console.log(afterTotalAmount, singleEnergytotalAmount, singleFueltotalAmount, buildFueltotalAmount, buildEnergytotalAmount, 'afterTotalAmount');
      this.formList.map(x => {
        if (x.fieldName == 'buildRebateFuelAmountStart') {
          //建店补贴直接带出池余额(油)
          x.initialValue = this.buildRebateFuelAmountStart;
        }
        if (x.fieldName == 'buildRebateFuelAmountEnd') {
          //建店补贴单车带出池余额(油)
          x.initialValue = this.buildRebateFuelAmountEnd;
        }
        if (x.fieldName == 'buildRebateEnergyAmountStart') {
          //建店补贴直接带出池余额(电)
          x.initialValue = this.buildRebateEnergyAmountStart;
        }
        if (x.fieldName == 'buildRebateEnergyAmountEnd') {
          //建店补贴单车带出池余额(电)
          x.initialValue = this.buildRebateEnergyAmountEnd;
        }
        if (x.fieldName == 'singleRebateFuelAmount') {
          //单车返利余额(油)
          x.initialValue = this.singleRebateFuelAmount;
        }
        if (x.fieldName == 'singleRebateEnergyAmount') {
          //单车返利余额(电)
          x.initialValue = this.singleRebateEnergyAmount;
        }
        if (x.fieldName == 'buildRebateFuelTotalAmountStart') {
          //建店补贴首使用金额(油)
          x.initialValue = buildRebateFuelAmountStart;
        }
        if (x.fieldName == 'buildRebateEnergyTotalAmountStart') {
          //建店补贴首使用金额(电)
          x.initialValue = buildRebateEnergyAmountStart;
        }
        if (x.fieldName == 'buildRebateEnergyTotalAmount') {
          //建店补贴尾使用金额(电)
          x.initialValue = buildEnergytotalAmount;
        }
        if (x.fieldName == 'buildRebateFuelTotalAmount') {
          //建店补贴尾使用金额(油)
          x.initialValue = buildFueltotalAmount;
        }
        if (x.fieldName == 'singleRebateEnergyTotalAmount') {
          //单车返利使用金额(电)
          x.initialValue = singleEnergytotalAmount;
        }
        if (x.fieldName == 'singleRebateFuelTotalAmount') {
          //单车返利使用金额(油)
          x.initialValue = singleFueltotalAmount;
        }
        if (x.fieldName == 'realPayTotalAmount') {
          //实付总金额
          x.initialValue = afterTotalAmount > 0 ? afterTotalAmount : 0;
        }
      });
    },
    reComputedTable(rowInfo) {
      rowInfo.afterTotalAmount = (rowInfo.afterDiscountAmount * rowInfo.orderNum).toFixed(2); //给后台算
      rowInfo.discountTotalAmount = (rowInfo.discountAmount * rowInfo.orderNum).toFixed(2); //给后台算
      rowInfo.totalAmount = ((rowInfo.singleAmount - (rowInfo.subsidyAmount ? rowInfo.subsidyAmount : 0)) * rowInfo.orderNum).toFixed(2); //给后台算

      //建首总额+单车返利总额
      let totalAmount = (rowInfo.singleAmount - (rowInfo.subsidyAmount ? rowInfo.subsidyAmount : 0)) * this.rate - rowInfo.discountAmount; //自己用
      if (this.formList.find(x => x.fieldName == 'isRebate').initialValue == 10041002 || totalAmount < 0) {
        totalAmount = 0;
      }
      let single = rowInfo.singleRebate == undefined ? rowInfo.singleRebateAmount : rowInfo.singleRebate; //单车返利总金额上线
      // let bulidStart = rowInfo.bulidRebateStart;//建店总金额
      let bulidEnd = rowInfo.bulidRebateEnd == undefined ? rowInfo.buildRebateAmount : rowInfo.bulidRebateEnd; //建店总金额 buildRebateAmount
      //初始化
      rowInfo.buildRebateTotalAmountStart = 0; //建店首总额
      rowInfo.buildRebateTotalAmount = 0; //建店尾总额
      rowInfo.singleRebateTotalAmount = 0; //单车返利总额
      rowInfo.buildRebateTotalAmountLocalShow = 0; //建店首总额+建店尾总额
      this.cache.singleRebateFuelAmount = this.singleRebateFuelAmount; //单车返利余额(油)
      this.cache.singleRebateEnergyAmount = this.singleRebateEnergyAmount; //单车返利余额(电)
      this.cache.buildRebateFuelAmountEnd = this.buildRebateFuelAmountEnd; //建店补贴单车带出池余额(油)
      this.cache.buildRebateFuelAmountStart = this.buildRebateFuelAmountStart; //建店补贴直接带出池余额(油)
      this.cache.buildRebateEnergyAmountEnd = this.buildRebateEnergyAmountEnd; //建店补贴单车带出池余额(电)
      this.cache.buildRebateEnergyAmountStart = this.buildRebateEnergyAmountStart; //建店补贴直接带出池余额(电)

      let singleFEnd = this.singleRebateFuelAmount; //单车返利余额(油)
      let singleFStart = this.singleRebateEnergyAmount; //单车返利余额(油)
      let buildFEnd = this.buildRebateFuelAmountEnd; //建店补贴单车带出池余额(油)
      let buildEEnd = this.buildRebateEnergyAmountEnd; //建店补贴单车带出池余额(油)
      let buildFStart = this.buildRebateFuelAmountStart; //建店补贴直接带出池余额(油)
      let buildFEStart = this.buildRebateEnergyAmountStart; //建店补贴直接带出池余额(油)

      console.log('首1', this.buildRebateFuelAmountStart);
      console.log('首2', this.buildRebateFuelAmountStartEdit);
      console.log('首3', this.buildRebateFuelAmountStart + this.buildRebateFuelAmountStartEdit);

      this.singleRebateFuelAmount = this.singleRebateFuelAmount + this.singleRebateFuelAmountEdit;
      this.buildRebateFuelAmountEnd = this.buildRebateFuelAmountEnd + this.buildRebateFuelAmountEndEdit;
      this.buildRebateFuelAmountStart = this.buildRebateFuelAmountStart + this.buildRebateFuelAmountStartEdit;
      this.singleRebateEnergyAmount = this.singleRebateEnergyAmount + this.singleRebateEnergyAmountEdit;
      this.buildRebateEnergyAmount = this.buildRebateEnergyAmountEnd + this.buildRebateEnergyAmountEndEdit;
      this.buildRebateEnergyAmountStart = this.buildRebateEnergyAmountStart + this.buildRebateEnergyAmountStartEdit;

      console.log('油车', rowInfo.powerType == 60081001);
      console.log('建首池油余额---', this.buildRebateFuelAmountStart); //50000
      console.log('建首总额+单车返利总额上线阀值---totalAmount', totalAmount); //建首总额+单车返利总额
      console.log('单车返利金额上线---single', single);
      console.log('建尾返利金额上线---bulidEnd', bulidEnd);
      for (let i = 0; i < rowInfo.orderNum; i++) {
        console.log('rowInfo.buildRebateType', rowInfo.buildRebateType);
        if (rowInfo.buildRebateType == 60361003) {
          if (rowInfo.powerType == 60081001) {
            //todo 默认使用建首逻辑
            if (totalAmount <= this.buildRebateFuelAmountStart) {
              //油建首池
              this.buildRebateFuelAmountStart = this.buildRebateFuelAmountStart - totalAmount;
              rowInfo.buildRebateTotalAmountStart += totalAmount; //建首总额
            } else {
              //油首池余额不够用
              if (this.buildRebateFuelAmountStart == 0) {
                //油建首池
                //todo 调用建尾逻辑
                // 燃油车
                let totalbulidEndSingle = bulidEnd + single;
                if (totalAmount <= totalbulidEndSingle) {
                  //当后台设定单车返利+建尾返利的和大于计算值totalAmount时
                  totalbulidEndSingle = totalAmount;
                }
                let bulidEndLocal = Math.min(bulidEnd, totalbulidEndSingle);
                if (bulidEndLocal >= this.buildRebateFuelAmountEnd) {
                  rowInfo.buildRebateTotalAmount += this.buildRebateFuelAmountEnd;
                  bulidEndLocal = this.buildRebateFuelAmountEnd;
                  this.buildRebateFuelAmountEnd = 0;
                } else {
                  this.buildRebateFuelAmountEnd -= bulidEndLocal;
                  rowInfo.buildRebateTotalAmount += bulidEndLocal;
                }

                let singleLocal = Math.min(totalbulidEndSingle - bulidEndLocal, single);
                if (singleLocal >= this.singleRebateFuelAmount) {
                  rowInfo.singleRebateTotalAmount += this.singleRebateFuelAmount;
                  this.singleRebateFuelAmount = 0;
                } else {
                  this.singleRebateFuelAmount -= singleLocal;
                  rowInfo.singleRebateTotalAmount += singleLocal;
                }
                console.log('rowInfo.singleRebateTotalAmount---', rowInfo.singleRebateTotalAmount);
              } else {
                let singleTotal = totalAmount - this.buildRebateFuelAmountStart;
                //建首总额
                rowInfo.buildRebateTotalAmountStart += this.buildRebateFuelAmountStart; //油建首池
                this.buildRebateFuelAmountStart = 0; //建店补贴首款余额(油)

                if (this.singleRebateFuelAmount == 0) {
                  //单车返利余额(油)池
                  rowInfo.singleRebateTotalAmount = 0;
                } else {
                  console.log('come in singleTotal', singleTotal);
                  if (singleTotal <= single) {
                    //小于上线
                    if (singleTotal >= this.singleRebateFuelAmount) {
                      //单车返利余额(油)池不足
                      rowInfo.singleRebateTotalAmount += this.singleRebateFuelAmount;
                      this.singleRebateFuelAmount = 0; //单车返利余额(油)池
                    } else {
                      //单车返利余额(油)够用
                      this.singleRebateFuelAmount = this.singleRebateFuelAmount - singleTotal;
                      rowInfo.singleRebateTotalAmount += singleTotal;
                    }
                  } else {
                    if (single >= this.singleRebateFuelAmount) {
                      //单车返利余额(油)池不足
                      rowInfo.singleRebateTotalAmount += this.singleRebateFuelAmount;
                      this.singleRebateFuelAmount = 0; //单车返利余额(油)池
                    } else {
                      //单车返利余额(油)够用
                      this.singleRebateFuelAmount = this.singleRebateFuelAmount - single;
                      rowInfo.singleRebateTotalAmount += single;
                    }
                  }
                }
              }
            }
          } else {
            //电车

            //todo 默认使用建首逻辑
            if (totalAmount <= this.buildRebateEnergyAmountStart) {
              //电建首池
              this.buildRebateEnergyAmountStart = this.buildRebateEnergyAmountStart - totalAmount;
              rowInfo.buildRebateTotalAmountStart += totalAmount; //建首总额
            } else {
              //电首池余额不够用
              if (this.buildRebateEnergyAmountStart == 0) {
                //电建首池
                //todo 调用建尾逻辑
                // 电动车
                let totalbulidEndSingle = bulidEnd + single;
                if (totalAmount <= totalbulidEndSingle) {
                  //当后台设定单车返利+建尾返利的和大于计算值totalAmount时
                  totalbulidEndSingle = totalAmount;
                }
                let bulidEndLocal = Math.min(bulidEnd, totalbulidEndSingle);
                if (bulidEndLocal >= this.buildRebateEnergyAmountEnd) {
                  rowInfo.buildRebateTotalAmount += this.buildRebateEnergyAmountEnd;
                  this.buildRebateEnergyAmountEnd = 0;
                } else {
                  this.buildRebateEnergyAmountEnd -= bulidEndLocal;
                  rowInfo.buildRebateTotalAmount += bulidEndLocal;
                }

                let singleLocal = Math.min(totalbulidEndSingle - bulidEndLocal, single);
                if (singleLocal >= this.singleRebateEnergyAmount) {
                  rowInfo.singleRebateTotalAmount += this.singleRebateEnergyAmount;
                  this.singleRebateEnergyAmount = 0;
                } else {
                  this.singleRebateEnergyAmount -= singleLocal;
                  rowInfo.singleRebateTotalAmount += singleLocal;
                }
              } else {
                let singleTotal = totalAmount - this.buildRebateEnergyAmountStart;
                //建首总额
                rowInfo.buildRebateTotalAmountStart += this.buildRebateEnergyAmountStart; //电建首池
                this.buildRebateEnergyAmountStart = 0; //建店补贴首款余额(电)

                if (this.singleRebateEnergyAmount == 0) {
                  //单车返利余额(电)池
                  rowInfo.singleRebateTotalAmount = 0;
                } else {
                  if (singleTotal <= single) {
                    //小于上线
                    if (singleTotal >= this.singleRebateEnergyAmount) {
                      //单车返利余额(电)池不足
                      rowInfo.singleRebateTotalAmount += this.singleRebateEnergyAmount;
                      this.singleRebateEnergyAmount = 0; //单车返利余额(电)池
                    } else {
                      //单车返利余额(电)够用
                      this.singleRebateEnergyAmount = this.singleRebateEnergyAmount - singleTotal;
                      rowInfo.singleRebateTotalAmount += singleTotal;
                    }
                  } else {
                    if (single >= this.singleRebateEnergyAmount) {
                      //单车返利余额(电)池不足
                      rowInfo.singleRebateTotalAmount += this.singleRebateEnergyAmount;
                      this.singleRebateEnergyAmount = 0; //单车返利余额(电)池
                    } else {
                      //单车返利余额(电)够用
                      this.singleRebateEnergyAmount = this.singleRebateEnergyAmount - single;
                      rowInfo.singleRebateTotalAmount += single;
                    }
                  }
                }
              }
            }
          }
        } else if (rowInfo.buildRebateType == 60361002) {
          //店尾
          if (rowInfo.powerType == 60081001) {
            //燃油
            //todo 调用建尾逻辑
            // 燃油车
            if (single >= this.singleRebateFuelAmount) {
              rowInfo.singleRebateTotalAmount += this.singleRebateFuelAmount;
              this.singleRebateFuelAmount = 0;
            } else {
              this.singleRebateFuelAmount = this.singleRebateFuelAmount - single;
              rowInfo.singleRebateTotalAmount += single;
            }
            if (bulidEnd >= this.buildRebateFuelAmountEnd) {
              rowInfo.buildRebateTotalAmount += this.buildRebateFuelAmountEnd;
              this.buildRebateFuelAmountEnd = 0;
            } else {
              this.buildRebateFuelAmountEnd = this.buildRebateFuelAmountEnd - bulidEnd;
              rowInfo.buildRebateTotalAmount += bulidEnd;
            }
            console.log('rowInfo.singleRebateTotalAmount---', rowInfo.singleRebateTotalAmount);
          } else {
            //todo 调用建尾逻辑
            // 电动车
            if (single >= this.singleRebateEnergyAmount) {
              rowInfo.singleRebateTotalAmount += this.singleRebateEnergyAmount;
              this.singleRebateEnergyAmount = 0;
            } else {
              rowInfo.singleRebateTotalAmount += single;
              this.singleRebateEnergyAmount = this.singleRebateEnergyAmount - single;
            }
            if (bulidEnd >= this.buildRebateEnergyAmountEnd) {
              rowInfo.buildRebateTotalAmount += this.buildRebateEnergyAmountEnd;
              this.buildRebateEnergyAmountEnd = 0;
            } else {
              rowInfo.buildRebateTotalAmount += bulidEnd;
              this.buildRebateEnergyAmountEnd = this.buildRebateEnergyAmountEnd - bulidEnd;
            }
          }
        }
      }
      rowInfo.buildRebateTotalAmountLocalShow = (
        (rowInfo.buildRebateTotalAmountStart ? rowInfo.buildRebateTotalAmountStart : 0) + (rowInfo.buildRebateTotalAmount ? rowInfo.buildRebateTotalAmount : 0)
      ).toFixed(2);
      rowInfo.singleRebateTotalAmount = rowInfo.singleRebateTotalAmount.toFixed(2);

      this.singleRebateFuelAmount = singleFEnd;
      this.buildRebateFuelAmountEnd = buildFEnd;
      this.buildRebateFuelAmountStart = buildFStart;
      this.singleRebateEnergyAmount = singleFStart;
      this.buildRebateEnergyAmount = buildEEnd;
      this.buildRebateEnergyAmountStart = buildFEStart;
      return rowInfo;
    }
  }
};
</script>
<style lang="less">
.discount {
  text-decoration: underline;
  color: #d1291a;
  cursor: pointer;
}
</style>
